package com.datawin.taotaocheche.ui.actviity.login.biz;

import com.datawin.taotaocheche.base.BaseBiz;
import com.datawin.taotaocheche.base.BaseResp;
import com.datawin.taotaocheche.bean.UserInfo;
import com.datawin.taotaocheche.comm.BaseSubscribe2;
import com.datawin.taotaocheche.comm.RetrofitHelp;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2017/10/21.
 */

public class LoginBiz  extends  BaseBiz{

    /**
     * 登录
     * @param phone
     * @param pwd
     * @param callback
     */
    public void Login(String phone, String pwd, String alias, String loginType,final BaseBiz.Callback<UserInfo> callback) {
        com.add(RetrofitHelp.getSecretApi().loginCheck(phone, pwd,alias,loginType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2<BaseResp<UserInfo>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((UserInfo) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((UserInfo) obj);
                    }
                })
        );
    }

    /**
     * 获取验证码
     *
     * @param phone
     * @param callback
     */
    public void mobileSms(String phone, Integer  type, final BaseBiz.Callback<Object> callback) {
        com.add(RetrofitHelp.getSecretApi().mobileSms(phone, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2<BaseResp<Object>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess(obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure(obj);
                    }
                })
        );
    }

    /**
     * 注册
     *
     * @param phone
     * @param pwd
     * @param callback
     */
    public void regCheck(String phone, String pwd, String loginType, String alias, final BaseBiz.Callback<UserInfo> callback) {
        com.add(RetrofitHelp.getSecretApi().regCheck(phone, pwd, loginType, alias)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe2<BaseResp<UserInfo>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((UserInfo) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((UserInfo) obj);
                    }
                })
        );
    }

}
